home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2003 December / The Sunday Times - The Month 2003-12.iso / pc / engine / shell / shell.swf / scripts / DefineSprite_70 / frame_1 / DoAction.as
Encoding:
Text File  |  2003-11-10  |  10.6 KB  |  506 lines

  1. function childLockSet(val)
  2. {
  3.    makeChildren(ndParent,true);
  4. }
  5. function make(section)
  6. {
  7.    active = true;
  8.    arrParentIndex = [];
  9.    SECTION_COLOR = Tardis.Colors.getHex(section);
  10.    SECTION_HALF_COLOR = Tardis.Colors.getHex(section + "50");
  11.    mc_title.txt.textColor = SECTION_COLOR;
  12.    mc_up.clr.setRGB(SECTION_HALF_COLOR);
  13.    xmlMenu = new XML();
  14.    xmlMenu.onLoad = build;
  15.    xmlMenu.load(Tardis.ASSETS_FOLDER + "xml/sections/" + section + ".xml");
  16. }
  17. function clearUp()
  18. {
  19.    mc_root.removeMovieClip();
  20.    delete mc_root;
  21.    delete mc_lock;
  22.    delete xmlMenu;
  23.    delete ItemHome;
  24.    delete ndPromo;
  25.    delete mcPromo;
  26.    delete ndParent;
  27.    animating = false;
  28.    hide();
  29. }
  30. function hide()
  31. {
  32.    _visible = false;
  33.    active = false;
  34. }
  35. function doOver(nm)
  36. {
  37.    mc_root["mc_i_" + nm].onRollOver(true);
  38. }
  39. function doOut(nm)
  40. {
  41.    mc_root["mc_i_" + nm].onRollOut(true);
  42. }
  43. function doUp(nm)
  44. {
  45.    mc_root["mc_i_" + nm].onRelease(true);
  46. }
  47. function setTitle(str)
  48. {
  49.    with(mc_title)
  50.    {
  51.       txt.htmlText = str.replace("\\n","<br>");
  52.       txt.textColor = SECTION_COLOR;
  53.       txt.resize();
  54.    }
  55. }
  56. function build()
  57. {
  58.    var ndRoot = xmlMenu.firstChild;
  59.    var ndStyle = ndRoot.byName("style");
  60.    strDefault = ndStyle.attributes["default"];
  61.    strDefaultUp = ndStyle.attributes.up;
  62.    ItemHome = ndRoot.byName("items").firstChild;
  63.    ndPromo = ndRoot.byName("promo");
  64.    _visible = true;
  65.    makeChildren(ItemHome);
  66.    onReady();
  67. }
  68. function clearAll()
  69. {
  70.    mc_root.removeMovieClip();
  71. }
  72. function makeChildren(nd, blnDontLoadPage)
  73. {
  74.    trace("makeChildren()");
  75.    var fadeItem = function(obj)
  76.    {
  77.       obj._alpha = 0;
  78.       obj.i = (i + 1) * 2;
  79.       if(obj.onEnterFrame != null)
  80.       {
  81.          trace("ERROR");
  82.       }
  83.       obj.onEnterFrame = itemFadeEnterFrame;
  84.    };
  85.    var createItem = function(strName)
  86.    {
  87.       var mc = mc_root.createEmptyMovieClip(strName,++mc_root.depth);
  88.       mc.createTextField("txt",0,0,0,167,10);
  89.       var strLabel = node.attributes.label.toString().replace("\\n","<br>");
  90.       with(mc.txt)
  91.       {
  92.          embedFonts = true;
  93.          selectable = false;
  94.          wordWrap = true;
  95.          html = true;
  96.          autoSize = "left";
  97.          htmlText = "<font face=\"TardisFGDemi\" size=\"" + nmTextSize + "\">" + strLabel + "</font>";
  98.          textColor = SECTION_HALF_COLOR;
  99.       }
  100.       mc.index = i;
  101.       if(i > 0)
  102.       {
  103.          var mc_p = mc_root["mc_i_" + (i - 1)];
  104.          mc._y = mc_p._y + mc_p._height + PADDING;
  105.       }
  106.       fadeItem(mc);
  107.       mc.sound = node.attributes.type != "html" ? "ContentLink" : "WebLink";
  108.       return mc;
  109.    };
  110.    if(nd == Tardis.ActiveItem && nd.attributes.type == "promo")
  111.    {
  112.       nd = Tardis.ActiveItem = ndPromo;
  113.    }
  114.    nmFading = 0;
  115.    objLastClicked = null;
  116.    clearAll();
  117.    if(nd == ItemHome)
  118.    {
  119.       setTitle(strDefault);
  120.       mc_up.hide();
  121.    }
  122.    else
  123.    {
  124.       setTitle(nd.attributes.label);
  125.       mc_up.show();
  126.    }
  127.    ndParent = nd;
  128.    this.createEmptyMovieClip("mc_root",++depth);
  129.    mc_root._x = 8;
  130.    if(nd.attributes.hidenavtitle == "true")
  131.    {
  132.       mc_root._y = 12;
  133.       setTitle("");
  134.    }
  135.    else
  136.    {
  137.       mc_root._y = mc_title._y + mc_title._height + 2;
  138.    }
  139.    nmItems = nd.childNodes.length;
  140.    var nmSpacingForItems = nd.attributes.spacingforitems;
  141.    nmSpacingForItems != null ? 0 : (nmSpacingForItems = nmItems);
  142.    if(nmSpacingForItems > 15)
  143.    {
  144.       padding = -6;
  145.       mc_root._y -= 6;
  146.    }
  147.    else if(nmSpacingForItems > 10)
  148.    {
  149.       padding = -3;
  150.    }
  151.    else
  152.    {
  153.       padding = 0;
  154.    }
  155.    var strPadding = nd.attributes.padding;
  156.    if(strPadding != null)
  157.    {
  158.       padding = parseInt(strPadding);
  159.    }
  160.    var strFontSize = nd.attributes.fontsize;
  161.    var nmTextSize = strFontSize == null ? (nmItems <= 15 ? 12 : 11) : parseInt(strFontSize);
  162.    var nmLeading = -1;
  163.    var strUpText;
  164.    var strParentUpText;
  165.    if(nd.parentNode == ItemHome)
  166.    {
  167.       strUpText = strDefaultUp;
  168.    }
  169.    else
  170.    {
  171.       strParentUpText = nd.parentNode.attributes.up;
  172.       if(strParentUpText != null)
  173.       {
  174.          strUpText = strParentUpText;
  175.       }
  176.       else
  177.       {
  178.          strUpText = nd.parentNode.attributes.label;
  179.       }
  180.    }
  181.    mc_up.txt.text = strUpText;
  182.    var node;
  183.    var strType;
  184.    var mc;
  185.    var i = 0;
  186.    while(i < nmItems)
  187.    {
  188.       node = nd.childNodes[i];
  189.       node.index = i;
  190.       mc = createItem("mc_i_" + i);
  191.       strType = node.attributes.type;
  192.       if(strType == "promo")
  193.       {
  194.          mc.onRollOver = pOver;
  195.          mc.onRollOut = pOut;
  196.          mc.onRelease = rUp;
  197.          mcPromo = mc;
  198.          mc.node = ndPromo;
  199.       }
  200.       else
  201.       {
  202.          mc.onRollOver = rOver;
  203.          mc.onRollOut = rOut;
  204.          mc.onRelease = rUp;
  205.          mc.node = node;
  206.          if(strType == "lock")
  207.          {
  208.             mc_lock = mc;
  209.          }
  210.       }
  211.       if(Tardis.ChildLock.active == true && (node.attributes.type == "html" || node.attributes.type == "promo"))
  212.       {
  213.          mc._y -= mc._height + PADDING;
  214.          mc._visible = false;
  215.       }
  216.       i++;
  217.    }
  218.    _xscale = 100;
  219.    if(nd.attributes.type == null && nd.firstChild.hasChildNodes() != true && blnDontLoadPage != true)
  220.    {
  221.       mc_root.mc_i_0.onRelease(null,true);
  222.    }
  223.    animating = true;
  224. }
  225. function rUp(fromContent, blnSilent)
  226. {
  227.    if(this == objLastClicked)
  228.    {
  229.       return undefined;
  230.    }
  231.    if(blnSilent == null)
  232.    {
  233.       Tardis.SFX.play(this.sound + "Click");
  234.    }
  235.    loadItem(this.node,0,this);
  236.    if(this.node.attributes.type != "inactive" && this.node.childNodes.length > 0)
  237.    {
  238.       arrParentIndex.push(this.index);
  239.       ndNext = this.node;
  240.       objLastClicked = this;
  241.       animating = true;
  242.       fadeDownOthers();
  243.       fadeDownFinished();
  244.    }
  245.    else
  246.    {
  247.       animating = false;
  248.       if(blnSilent == null)
  249.       {
  250.          onComplete();
  251.       }
  252.    }
  253. }
  254. function rOver(fromContent)
  255. {
  256.    if(this != objLastClicked)
  257.    {
  258.       Tardis.SFX.play(this.sound + "Over");
  259.       if(fromContent != true)
  260.       {
  261.          EB.broadcastMessage("doOver",this.index);
  262.       }
  263.       this.txt.textColor = SECTION_COLOR;
  264.    }
  265. }
  266. function rOut(fromContent)
  267. {
  268.    if(this != objLastClicked)
  269.    {
  270.       if(fromContent != true)
  271.       {
  272.          EB.broadcastMessage("doOut",this.index);
  273.       }
  274.       this.txt.textColor = SECTION_HALF_COLOR;
  275.    }
  276. }
  277. function itemFadeEnterFrame()
  278. {
  279.    with(this)
  280.    {
  281.       i--;
  282.       if(i <= 0)
  283.       {
  284.          _alpha += 100;
  285.          if(_alpha >= 100)
  286.          {
  287.             onEnterFrame = null;
  288.             fadeUpFinished();
  289.          }
  290.       }
  291.    }
  292. }
  293. function fadeUpFinished()
  294. {
  295.    nmFading++;
  296.    if(nmFading == nmItems)
  297.    {
  298.       animating = false;
  299.       onComplete();
  300.    }
  301. }
  302. function fadeDownOthers()
  303. {
  304.    nmFading = 0;
  305.    var mc;
  306.    var i = 0;
  307.    while(i < nmItems)
  308.    {
  309.       mc = mc_root["mc_i_" + i];
  310.       if(mc != objLastClicked)
  311.       {
  312.          mc.i = (len - i + 1) * 2;
  313.          if(mc.onEnterFrame != null)
  314.          {
  315.             trace("ERROR!");
  316.          }
  317.          mc.onEnterFrame = itemFadeUpEnterFrame;
  318.       }
  319.       i++;
  320.    }
  321. }
  322. function fadeDownFinished()
  323. {
  324.    nmFading++;
  325.    if(nmFading == nmItems)
  326.    {
  327.       makeChildren(ndNext);
  328.    }
  329. }
  330. function itemFadeUpEnterFrame()
  331. {
  332.    with(this)
  333.    {
  334.       i--;
  335.       if(i <= 0)
  336.       {
  337.          _alpha -= 40;
  338.          if(_alpha <= 0)
  339.          {
  340.             onEnterFrame = null;
  341.             fadeDownFinished();
  342.          }
  343.       }
  344.    }
  345. }
  346. function doPromoUp()
  347. {
  348.    if(typeof mcPromo == "movieclip")
  349.    {
  350.       mcPromo.onRelease(true);
  351.    }
  352.    else
  353.    {
  354.       Tardis.itemGo(ndPromo);
  355.    }
  356. }
  357. function doPromoOver()
  358. {
  359.    mcPromo.onRollOver(true);
  360. }
  361. function doPromoOut()
  362. {
  363.    mcPromo.onRollOut(true);
  364. }
  365. function pOver(fromContent)
  366. {
  367.    if(this != objLastClicked)
  368.    {
  369.       Tardis.SFX.play(this.sound + "Over");
  370.       if(fromContent != true)
  371.       {
  372.          EB.broadcastMessage("doPromoOver");
  373.       }
  374.       this.txt.textColor = SECTION_COLOR;
  375.    }
  376. }
  377. function pOut(fromContent)
  378. {
  379.    if(this != objLastClicked)
  380.    {
  381.       if(fromContent != true)
  382.       {
  383.          EB.broadcastMessage("doPromoOut");
  384.       }
  385.       this.txt.textColor = SECTION_HALF_COLOR;
  386.    }
  387. }
  388. hide();
  389. stop();
  390. o = ASBroadcaster;
  391. o._broadcastMessage = function()
  392. {
  393.    var a = this._listeners.concat();
  394.    var e = arguments.shift();
  395.    for(var i in a)
  396.    {
  397.       a[i][e].apply(a[i],arguments);
  398.    }
  399. };
  400. o.addListener = function(obj)
  401. {
  402.    var a = this._listeners;
  403.    var i = a.length;
  404.    a[-1] = obj;
  405.    while(a[--i] != obj)
  406.    {
  407.    }
  408.    delete a[-1];
  409.    if(i < 0)
  410.    {
  411.       a.unshift(obj);
  412.       this.broadcastMessage = ASBroadcaster._broadcastMessage;
  413.       return true;
  414.    }
  415.    return false;
  416. };
  417. o.removeListener = function(obj)
  418. {
  419.    var a = this._listeners;
  420.    var i = a.length;
  421.    a[-1] = obj;
  422.    while(a[--i] != obj)
  423.    {
  424.    }
  425.    delete a[-1];
  426.    if(i >= 0)
  427.    {
  428.       a.splice(i,1);
  429.       if(a.length == 0)
  430.       {
  431.          this.broadcastMessage = undefined;
  432.       }
  433.       return true;
  434.    }
  435.    return false;
  436. };
  437. o.initialize = function(obj)
  438. {
  439.    obj.broadcastMessage = undefined;
  440.    obj.addListener = AsBroadcaster.addListener;
  441.    obj.removeListener = AsBroadcaster.removeListener;
  442.    obj._listeners = [];
  443.    AsSetPropFlags(obj,"broadcastMessage,addListener,removeListener,_listeners",131);
  444. };
  445. ASSetPropFlags(o,null,131);
  446. delete o;
  447. EB = {};
  448. ASBroadcaster.initialize(EB);
  449. active = false;
  450. animating = false;
  451. Tardis.ChildLock.EB.addListener(this);
  452. DEFAULT_COLOR = 12235927;
  453. with(mc_title.txt)
  454. {
  455.    autoSize = "left";
  456.    wordWrap = true;
  457. }
  458. mc_up.clr = new Color(mc_up);
  459. mc_up.onRollOver = function()
  460. {
  461.    Tardis.SFX.play("NavOver");
  462.    this.clr.setRGB(SECTION_COLOR);
  463. };
  464. mc_up.onRollOut = function()
  465. {
  466.    this.clr.setRGB(SECTION_HALF_COLOR);
  467. };
  468. mc_up.onRelease = function()
  469. {
  470.    if(animating == true)
  471.    {
  472.       return undefined;
  473.    }
  474.    Tardis.SFX.play("NavClick");
  475.    clearAll();
  476.    var ndUp = ndParent.parentNode;
  477.    Tardis.itemGo(ndUp);
  478.    makeChildren(ndUp);
  479.    arrParentIndex.pop();
  480. };
  481. mc_up.show = function()
  482. {
  483.    this._visible = true;
  484. };
  485. mc_up.hide = function()
  486. {
  487.    this._visible = false;
  488. };
  489. mc_up.hide();
  490. loadItem = function(node, calledFromCredits, mcItem)
  491. {
  492.    if(Tardis.itemGo(node) == true)
  493.    {
  494.       mcItem.txt.textColor = SECTION_COLOR;
  495.       objLastClicked.txt.textColor = SECTION_HALF_COLOR;
  496.       objLastClicked = mcItem;
  497.    }
  498.    if(calledFromCredits == 1)
  499.    {
  500.       animating = false;
  501.       onComplete();
  502.    }
  503. };
  504. var nmFading = 0;
  505. var mcPromo;
  506.